package com.test.io.basic;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author rgsmaster
 * @date 2024/7/23 9:46
 * @description
 */
public class Server {

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8565);
        System.out.println("server start...");

        Socket socket = serverSocket.accept();
        System.out.println("server accept...");

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String line = bufferedReader.readLine();
        System.out.println("客户端发送的消息为 received: " + line);


        PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true);
        printWriter.println("服务端已收到消息");

        // 关闭资源
        bufferedReader.close();
        printWriter.close();
        socket.close();
        serverSocket.close();
    }

    /**
     *
     * io流：内存-----数据源，的一个过程
     * 输入：数据源到内存‘
     * 输出：内存到数据源
     *
     * 分为字符流，字节流    inputStream   outputStream    Writer  Reader
     * InputStream	        OutputStream	        Reader	        Writer
     * FileInputStream	    FileOutputStream	    FileReader	    FileWriter
     * ByteArrayInputStream	ByteArrayOutputStream	CharArrayReader	CharArrayWriter
     * PipedInputStream	    PipedOutputStream	    PipedReader	    PipedWriter
     *                                              StringReader	StringWriter
     *
     *
     *
     *
     *
     */
}
